package com.zsl.util;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class C3P0Util {
    private static ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource("mysqlRemote");

    public static Connection getConnection() {
        Connection conn = null;
        try {
            //conn = DriverManager.getConnection(url, name, pwd);
            conn = comboPooledDataSource.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }

    public static void release(Statement stmt, Connection conn, ResultSet rs) {
        try {
            if (rs != null) {
                rs.close();
                rs = null; // 垃圾回收，上！
            }
            if (stmt != null) {
                stmt.close();
                stmt = null; // 垃圾回收，上！
            }
            if (conn != null) {
                conn.close();
                conn = null; // 垃圾回收，上！
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
